﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceEntity.BLL
{
    public class DeviceBLL
    {
        /// <summary>
        /// 获取PLC配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="ip">IP地址</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetPlcModel(Model.TypeModel.Type type,string name, string ip)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //欧姆龙系列
                case Model.TypeModel.Type.PLC_Omron_NJNX:
                    deviceConfig.type = type;
                    deviceConfig.mode = "TCP/IP";
                    deviceConfig.addr = ip;
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取PLC操作对象
        /// </summary>
        /// <param name="deviceConfig">PLC配置参数</param>
        /// <returns></returns>
        public static Device.Plc.BLL.IPlcBLL GetPlcBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //欧姆龙系列
                case Model.TypeModel.Type.PLC_Omron_NJNX: return Device.Plc.Type.OmronBLL.Init(deviceConfig);
                default:
                    return null; 
            }
        }

        /// <summary>
        /// 获取RFID配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="port">串口号</param>
        /// <param name="baundrate">波特率</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetRfidModel(Model.TypeModel.Type type,string name, string port, int baundrate)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //南京陆加壹
                case Model.TypeModel.Type.RFID_LiuJiaYi_LJYZN107:
                    deviceConfig.type = type;
                    deviceConfig.name = name;
                    deviceConfig.mode = "RS232";
                    deviceConfig.port = port;
                    deviceConfig.parameter = baundrate.ToString();
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取RFID操作对象
        /// </summary>
        /// <param name="deviceConfig">配置参数</param>
        /// <returns></returns>
        public static Device.Rfid.BLL.IRfidBLL GetRfidBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //南京陆加壹
                case Model.TypeModel.Type.RFID_LiuJiaYi_LJYZN107: return Device.Rfid.Type.LuJiaYiBLL.Init(deviceConfig);
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取测试箱配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="ip">IP地址</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetTestBoxModel(Model.TypeModel.Type type,string name, string ip)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //盟讯
                case Model.TypeModel.Type.TestBox_Common_MX:
                    deviceConfig.type = type;
                    deviceConfig.name = name;
                    deviceConfig.mode = "TCP/IP";
                    deviceConfig.addr = ip;
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取测试箱操作对象
        /// </summary>
        /// <param name="deviceConfig">配置参数</param>
        /// <returns></returns>
        public static Device.TestBox.BLL.ITestBoxBLL GetTestBoxBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //盟讯
                case Model.TypeModel.Type.TestBox_Common_MX: return Device.TestBox.Type.CommonBLL.Init(deviceConfig);
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取电气控制板配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="port">串口号</param>
        /// <param name="baundrate">波特率</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetElecPcbModel(Model.TypeModel.Type type,string name, string port, int baundrate)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //盟讯
                case Model.TypeModel.Type.ElecPcb_Common_MX:
                    deviceConfig.type = type;
                    deviceConfig.name = name;
                    deviceConfig.mode = "RS232";
                    deviceConfig.port = port;
                    deviceConfig.parameter = baundrate.ToString();
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取电气控制板操作对象
        /// </summary>
        /// <param name="deviceConfig">配置参数</param>
        /// <returns></returns>
        public static Device.ElecPcb.BLL.IElecPcbBLL GetElecPcbBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //盟讯
                case Model.TypeModel.Type.ElecPcb_Common_MX: return Device.ElecPcb.Type.CommonBLL.Init(deviceConfig);
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取电机配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="port">串口号</param>
        /// <param name="baundrate">波特率</param>
        /// <param name="addr">485地址</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetMotorModel(Model.TypeModel.Type type,string name, string port, int baundrate,int addr)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //雷赛
                case Model.TypeModel.Type.Motor_Leadshine_DM2C:
                    deviceConfig.type = type;
                    deviceConfig.name = name;
                    deviceConfig.mode = "RS485";
                    deviceConfig.port = port;
                    deviceConfig.addr = addr.ToString();
                    deviceConfig.parameter = baundrate.ToString();
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取电机操作对象
        /// </summary>
        /// <param name="deviceConfig">配置参数</param>
        /// <returns></returns>
        public static Device.Motor.BLL.IMotorBLL GetMotorBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //雷赛
                case Model.TypeModel.Type.Motor_Leadshine_DM2C: return Device.Motor.Type.LeadshineBLL.Init(deviceConfig);
                default:
                    return null;
            }
        }

        /// <summary>
        /// 获取相机配置参数
        /// </summary>
        /// <param name="type">型号</param>
        /// <param name="name">标识</param>
        /// <param name="ip">ip</param>
        /// <returns></returns>
        public static Model.DeviceConfigModel GetCameraModel(Model.TypeModel.Type type, string name, string ip)
        {
            Model.DeviceConfigModel deviceConfig = new Model.DeviceConfigModel();
            switch (type)
            {
                //海康
                case Model.TypeModel.Type.Motor_Leadshine_DM2C:
                    deviceConfig.type = type;
                    deviceConfig.name = name;
                    deviceConfig.mode = "TCP/IP";
                    deviceConfig.addr = ip;
                    return deviceConfig;
                default:
                    return null;
            }
        }
        /// <summary>
        /// 获取相机操作对象
        /// </summary>
        /// <param name="deviceConfig">配置参数</param>
        /// <returns></returns>
        public static Device.Camera.BLL.ICameraBLL GetCameraBLL(Model.DeviceConfigModel deviceConfig)
        {
            switch (deviceConfig.type)
            {
                //海康
                case Model.TypeModel.Type.Camera_Hikvision: return Device.Camera.Type.HikvisionBLL.Init(deviceConfig);
                default:
                    return null;
            }
        }
    }
}
